package com.goldcn.orderborrow.controller;

import com.goldcn.orderborrow.dto.UpdateGoodsCartBorrowDto;
import com.goldcn.orderborrow.service.GoodsCartBorrowService;
import com.goldcn.orderborrow.vo.GoodsCartBorrowVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:借货购物车控制器
 * @Author Tim Peng
 * @date 2017-4-19 18:18:28
 * @version V1.0
 */
@RestController
@RequestMapping("/cartborrow")
@Api(value = "借货箱", description = "借货箱微服务")
public class GoodsCartBorrowController {
    @Autowired
    private GoodsCartBorrowService goodsCartBorrowService;

    @ApiOperation(value="添加借货商品至我的借货箱")
    @RequestMapping(method = RequestMethod.POST)
    public Object addMyShoppingCart(@RequestBody GoodsCartBorrowVo goodsCartBorrowVo){
        return goodsCartBorrowService.addMyShoppingCart(goodsCartBorrowVo);
    }

    @ApiOperation(value="从借货箱移除我的借货商品(批量)")
    @RequestMapping(value = "/remove",method = RequestMethod.POST)
    public Object removeMyShoppingCart(@RequestBody List<Long> cartIDs){
        return goodsCartBorrowService.removeMyShoppingCart(cartIDs);
    }

    @ApiOperation(value="清空借货箱")
    @RequestMapping(value = "/clear/{userID}",method = RequestMethod.DELETE)
    public Object clearMyShoppingCart(@PathVariable Long userID){
        return goodsCartBorrowService.clearMyShoppingCart(userID);
    }

    @ApiOperation(value="查询我的借货箱")
    @RequestMapping(value = "/{userID}/{pageSize}/{pageNum}",method = RequestMethod.GET)
    public Object queryMyShoppingCart(@PathVariable Long userID,@PathVariable Integer pageNum,@PathVariable Integer pageSize){
        return goodsCartBorrowService.queryMyShoppingCart(userID,pageNum,pageSize);
    }

    @ApiOperation(value="修改我的借货箱商品信息")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Object updateGoodsCartInfo(@RequestBody List<UpdateGoodsCartBorrowDto> record){
        return goodsCartBorrowService.updateGoodsCartInfo(record);
    }

    @ApiOperation(value="查询商品库存")
    @RequestMapping(value = "/retInventory",method = RequestMethod.POST)
    public Object retInventory(@RequestBody Long skuID){
        return goodsCartBorrowService.retInventory(skuID);
    }

}
